﻿using Maple.Weixin.MP.Entities;
using Maple.Weixin.MP.Entities.Messages;

namespace Maple.Weixin.MP.Web
{
    /// <summary>
    /// 默认的一个消息响应服务。
    /// 该默认实现仅用于演示，实际使用可以自己继承ResponseServiceBase基类。
    /// </summary>
    public sealed class GettingRequestMessageTypeService : ResponseServiceBase
    {
        #region Overrides of ResponseServiceBase<IWeixinServiceSetting>

        public override ResponseMessageBase Handle(RequestMessageBase requestMessage) {
            var messageTypeName = "";
            switch (requestMessage.MsgType) {
                case RequestMessageType.Image:
                    messageTypeName = "image";
                    break;
                case RequestMessageType.Link:
                    messageTypeName = "link";
                    break;
                case RequestMessageType.Location:
                    messageTypeName = "location";
                    break;
                case RequestMessageType.Text:
                    messageTypeName = "text";
                    break;
                case RequestMessageType.Video:
                    messageTypeName = "video";
                    break;
                case RequestMessageType.Voice:
                    messageTypeName = "voice";
                    break;
                case RequestMessageType.Event:
                    var reqeustMessageEvent = (RequestMessageEventBase) requestMessage;
                    switch (reqeustMessageEvent.Event)
                    {
                        case Event.CLICK:
                            messageTypeName = "click event";
                            break;
                        case Event.LOCATION:
                            messageTypeName = "location event";
                            break;
                        case Event.scan:
                            messageTypeName = "scan event";
                            break;
                        case Event.subscribe:
                            messageTypeName = "subscribe event";
                            break;
                        case Event.unsubscribe:
                            messageTypeName = "unsubscribe event";
                            break;
                        case Event.VIEW:
                            messageTypeName = "view event";
                            break;
                    }
                    break;
            }
            messageTypeName = "This is " + messageTypeName;

            var responseMessage = requestMessage.CreateTextResponse(messageTypeName);
            return responseMessage;
        }

        #endregion
    }
}
